package com.springdoor.wx.api.controller;

import com.springdoor.wx.api.entity.SprdGoodsCollect;
import com.springdoor.wx.api.service.SprdGoodsCollectService;
import com.springdoor.wx.core.controller.BaseController;
import com.springdoor.wx.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RequestMapping("coll")
@RestController
public class SprdGoodsCollectController extends BaseController {

    @Autowired
    private SprdGoodsCollectService collectService;

    @RequestMapping("findList")
    public AjaxResult findCollList() {
        return success(collectService.findListByUserId(getUserId()));
    }

    @RequestMapping("getCollNum")
    public AjaxResult findCollNum() {
        return success(collectService.findCollNumByUserId(getUserId()));
    }

    @RequestMapping("findCollByGShopId")
    public AjaxResult findCollByGShopId(@RequestBody Map<String, String> map) {
        SprdGoodsCollect coll = new SprdGoodsCollect();
        coll.setGshopId(map.get("skuId"));
        coll.setUserId(getUserId());
        return success(collectService.findCollByGShopId(coll));
    }

    @PostMapping("insertColl")
    public AjaxResult insertSprdGoodsCollect(@RequestBody Map<String, String> map) {
        SprdGoodsCollect coll = new SprdGoodsCollect();
        coll.setGshopId(map.get("skuId"));
        coll.setUserId(getUserId());
        String username = getUsername();
        coll.setCreateBy(username);
        coll.setUpdateBy(username);
        return toAjax(collectService.insertSprdGoodsCollect(coll));
    }

    @PostMapping("cancelColl")
    public AjaxResult cancelColl(@RequestBody Map<String, String> map) {
        SprdGoodsCollect coll = new SprdGoodsCollect();
        coll.setDelFlag("1");
        coll.setUpdateBy(getUsername());
        coll.setGshopId(map.get("skuId"));
        coll.setUserId(getUserId());
        return toAjax(collectService.updateSprdGoodsCollect(coll));
    }

    @PostMapping("updateColl")
    public AjaxResult updateSprdGoodsCollect(@RequestBody SprdGoodsCollect sprdGoodsCollect) {
        sprdGoodsCollect.setUpdateBy(getUsername());
        return toAjax(collectService.updateSprdGoodsCollect(sprdGoodsCollect));
    }
}
